package com.jiutong.meipenggang.ui.activitys;


import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiutong.meipenggang.R;
import com.jiutong.meipenggang.base.AppManager;
import com.jiutong.meipenggang.base.BaseActivity;
import com.jiutong.meipenggang.base.CommonAdapter;
import com.jiutong.meipenggang.base.ViewHolder;
import com.jiutong.meipenggang.utils.DensityUtil;
import com.jiutong.meipenggang.views.popwindow.BasePopupWindow;
import com.jiutong.meipenggang.views.popwindow.TradeChoicePop;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TradeRecordActivity extends BaseActivity {


    @Bind(R.id.tv_common_title)
    TextView tvCommonTitle;
    @Bind(R.id.lv_trade_record)
    ListView lvTradeRecord;
    @Bind(R.id.tv_trade_record_hint)
    TextView tvTradeRecordHint;
    @Bind(R.id.iv_trade_logo)
    ImageView iv_trade_logo;
    @Bind(R.id.tv_common_title_options)
    TextView tvCommonTitleOptions;

    private PopupWindow mPopWindow;

//    private List<TradeRecordRespond> listAll;
//    private List<TradeRecordRespond> listIn;
//    private List<TradeRecordRespond> listOut;
    private TextView tv_all;
    private TextView tv_in;
    private TextView tv_out;

    @Override
    public int getLayoutResouceId() {
        return R.layout.activity_trade_record;
    }

    @Override
    protected void initView() {
        super.initView();

        tvCommonTitle.setText("交易记录");

//        if (listAll != null && listAll.size() > 0) {
//            tvCommonTitleOptions.setText("筛选");
//            tvCommonTitleOptions.setVisibility(View.VISIBLE);
//            tvCommonTitleOptions.setClickable(true);
//            tvTradeRecordHint.setVisibility(View.GONE);
//            lvTradeRecord.setVisibility(View.VISIBLE);
//            iv_trade_logo.setVisibility(View.GONE);
////            TradeRecordAdapter adapter = new TradeRecordAdapter(mContext, listAll, R.layout.item_trade_record);
////            lvTradeRecord.setAdapter(adapter);
//        } else {
//            tvCommonTitleOptions.setVisibility(View.GONE);
//            tvCommonTitleOptions.setClickable(false);
//            tvTradeRecordHint.setVisibility(View.VISIBLE);
//            lvTradeRecord.setVisibility(View.GONE);
//            iv_trade_logo.setVisibility(View.VISIBLE);
//        }
    }

    @Override
    protected void initDate(Bundle savedInstanceState) {
        super.initDate(savedInstanceState);
//        listAll = new ArrayList<>();
//        listIn = new ArrayList<>();
//        listOut = new ArrayList<>();
//        listAll.add(new TradeRecordRespond("美财宝", "日期 : 2017-09-01", "转入", "成功", "100元"));
//        listAll.add(new TradeRecordRespond("美财宝", "日期 : 2017-09-01", "转出", "成功", "200元"));
//        listAll.add(new TradeRecordRespond("美财宝", "日期 : 2017-09-01", "转入", "失败", "100元"));
//        listAll.add(new TradeRecordRespond("美财宝", "日期 : 2017-09-01", "转入", "成功", "100元"));
//        listAll.add(new TradeRecordRespond("美财宝", "日期 : 2017-09-01", "转出", "成功", "200元"));
//        for (int i = 0; i < listAll.size(); i++) {
//            if (listAll.get(i).getInOrOut().equals("转入")) {
//                listIn.add(new TradeRecordRespond(listAll.get(i).getDescrible(), listAll.get(i).getTime(),
//                        listAll.get(i).getInOrOut(), listAll.get(i).getResult(), listAll.get(i).getMoney()));
//            } else if (listAll.get(i).getInOrOut().equals("转出")) {
//                listOut.add(new TradeRecordRespond(listAll.get(i).getDescrible(), listAll.get(i).getTime(),
//                        listAll.get(i).getInOrOut(), listAll.get(i).getResult(), listAll.get(i).getMoney()));
//            }
//        }
    }

    @OnClick({R.id.rl_common_title_back, R.id.tv_common_title_options})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_common_title_back:
                AppManager.getAppManager().finishActivity(this);
                break;
            case R.id.tv_common_title_options:
//                showPopupWindow();
                break;
        }
    }

    //设置筛选未选中的样式状态
    private void setStyle() {
        tv_all.setTextColor(mContext.getResources().getColor(R.color.hongbao_table_gray));
        tv_all.setBackgroundResource(0);
        tv_in.setTextColor(mContext.getResources().getColor(R.color.hongbao_table_gray));
        tv_in.setBackgroundResource(0);
        tv_out.setTextColor(mContext.getResources().getColor(R.color.hongbao_table_gray));
        tv_out.setBackgroundResource(0);
    }

//    //筛选
//    public void showPopupWindow() {
//        View contentView = LayoutInflater.from(this).inflate(R.layout.pop_trade_choice, null);
//        mPopWindow = new PopupWindow(contentView,
//                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
//        mPopWindow.setContentView(contentView);
//        mPopWindow.setFocusable(true);
//        mPopWindow.setBackgroundDrawable(new BitmapDrawable());
//        mPopWindow.setOutsideTouchable(true);
//        //设置各个控件的点击响应
//        tv_all = (TextView) contentView.findViewById(R.id.tv_pop_trade_record_all);
//        tv_in = (TextView) contentView.findViewById(R.id.tv_pop_trade_record_in);
//        tv_out = (TextView) contentView.findViewById(R.id.tv_pop_trade_record_out);
//        final LinearLayout ll_evaluate_choose_pop = (LinearLayout) contentView.findViewById(R.id.ll_pop_trade_record_choice);
////        final HousePgListRespond respond = new HousePgListRespond();
//        tv_all.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                setStyle();
//                tv_all.setTextColor(mContext.getResources().getColor(R.color.common_blue));
//                tv_all.setBackgroundResource(R.color.pop_trade_record_bg);
//                TradeRecordAdapter adapter = new TradeRecordAdapter(mContext, listAll, R.layout.item_trade_record);
//                lvTradeRecord.setAdapter(adapter);
//                adapter.notifyDataSetChanged();
//            }
//        });
//        tv_in.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                setStyle();
//                tv_in.setTextColor(mContext.getResources().getColor(R.color.common_blue));
//                tv_in.setBackgroundResource(R.color.pop_trade_record_bg);
//                Log.d("listIn",listIn.toString());
//                TradeRecordAdapter adapter = new TradeRecordAdapter(mContext, listIn, R.layout.item_trade_record);
//                lvTradeRecord.setAdapter(adapter);
//                adapter.notifyDataSetChanged();
//            }
//        });
//        tv_out.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                setStyle();
//                tv_out.setTextColor(mContext.getResources().getColor(R.color.common_blue));
//                tv_out.setBackgroundResource(R.color.pop_trade_record_bg);
//                TradeRecordAdapter adapter = new TradeRecordAdapter(mContext, listOut, R.layout.item_trade_record);
//                lvTradeRecord.setAdapter(adapter);
//                adapter.notifyDataSetChanged();
//            }
//        });
//
//        int width = tvCommonTitleOptions.getWidth();
//        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
//        layoutParams.rightMargin = width / 2;
//        ll_evaluate_choose_pop.setLayoutParams(layoutParams);
//        mPopWindow.showAsDropDown(tvCommonTitleOptions, 0, 0);
//    }


//    public class TradeRecordAdapter extends CommonAdapter<TradeRecordRespond> {
//        public TradeRecordAdapter(Context context, List<TradeRecordRespond> listDatas, int layoutId) {
//            super(context, listDatas, layoutId);
//        }
//
//        @Override
//        protected void fillData(ViewHolder holder, int position) {
//            TextView tv_describe = holder.getView(R.id.tv_item_trade_describe);
//            TextView tv_time = holder.getView(R.id.tv_item_trade_time);
//            TextView tv_status = holder.getView(R.id.tv_item_trade_status);
//            TextView tv_money = holder.getView(R.id.tv_item_trade_money);
//            tv_describe.setText(listDatas.get(position).getDescrible());
//            tv_time.setText(listDatas.get(position).getTime());
//            tv_status.setText(listDatas.get(position).getInOrOut() + "  " + listDatas.get(position).getResult());
//            if (listDatas.get(position).getResult().equals("失败")) {
//                tv_status.setTextColor(getResources().getColor(R.color.trade_record_red));
//                tv_money.setTextColor(getResources().getColor(R.color.trade_record_red));
//            } else {
//                tv_status.setTextColor(getResources().getColor(R.color.trade_gray));
//                tv_money.setTextColor(getResources().getColor(R.color.trade_gray));
//            }
//            tv_money.setText(listDatas.get(position).getMoney());
//        }
//
//    }

}
